from flask import Flask, request, jsonify
from flask_cors import CORS
from user_authentication import register_user, login_user

app = Flask(__name__)
CORS(app)

@app.route('/register', methods=['POST'])
def register():
    """
    处理用户注册请求
    """
    data = request.get_json()
    username = data.get('username')
    password = data.get('password')
    if username and password:
        return register_user(username, password)
    else:
        return jsonify({"error": "请提供用户名和密码"}), 400

@app.route('/login', methods=['POST'])
def login():
    """
    处理用户登录请求
    """
    data = request.get_json()
    username = data.get('username')
    password = data.get('password')
    if username and password:
        return login_user(username, password)
    else:
        return jsonify({"error": "请提供用户名和密码"}), 400

if __name__ == '__main__':
    app.run(debug=True)